import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import net.coobird.thumbnailator.Thumbnails;

/**
 *
 */
public class ThumbnailsTool {


    public static void resize(String imgPath, double factor) throws IOException {

        File localTempFile = new File(imgPath);

        BufferedImage bufferedImage = ImageIO.read(localTempFile);
        int width = (int) (bufferedImage.getWidth() * factor);
        int height = (int) (bufferedImage.getHeight() * factor);

        // BufferedImage 第三方库压缩图片画幅。JDK自带的会有严重色差
        Thumbnails.of(localTempFile)
            .size(width, height)
            .outputFormat("jpg")
            .toFile(new File("image2.jpg"));

    }

}
